package {
	
	import ascb.util.NumberUtilities;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class die extends Sprite {
		
		public var _bouton:Sprite;
		
		public var _die:Sprite;
		public var _die2:Sprite;
		
		public var _value:uint;
		public var _value2:uint;
		
		public function die( ) {
			_die = new Sprite( );
			addChild(_die);
						
			_die2 = new Sprite( );
			addChild(_die2);
			
			//AJOUTE UN BOUTON POUR FAIRE ROULER LES DES
			_bouton = new Sprite();
			addChild(_bouton);
			_bouton.graphics.beginFill(0x0000FF);
			_bouton.graphics.drawCircle(80,80,8);
			_bouton.graphics.endFill( );
			_bouton.addEventListener(MouseEvent.CLICK, rollDie);
			
			rollDie(null);
		}
		
		private function rollDie(event:MouseEvent):void 
		{
			_value = NumberUtilities.random(1, 6);
			_die.graphics.clear( );
			_die.graphics.lineStyle(5);
			_die.graphics.beginFill(0xFFFFFF);
			_die.graphics.drawRect(0, 0, 50, 50);
			_die.graphics.endFill( );
			_die.graphics.beginFill(0x000000);
			if(_value == 1 || _value == 3 || _value == 5) {
				_die.graphics.drawCircle(25, 25, 4);
			}
			if(_value == 2 || _value == 3 || _value == 4 ||
				_value == 5 || _value == 6)
			{
				_die.graphics.drawCircle(11, 11, 4);
				_die.graphics.drawCircle(39, 39, 4);
			}
			if(_value == 4 || _value == 5 || _value == 6) {
				_die.graphics.drawCircle(11, 39, 4);
				_die.graphics.drawCircle(39, 11, 4);
			}
			if(_value == 6) {
				_die.graphics.drawCircle(11, 25, 4);
				_die.graphics.drawCircle(39, 25, 4);
			}
			
			_value2 = NumberUtilities.random(1, 6);
			_die2.graphics.clear( );
			_die2.graphics.lineStyle(5);
			_die2.graphics.beginFill(0xFFFFFF);
			_die2.graphics.drawRect(60, 0, 50, 50);
			_die2.graphics.endFill( );
			_die2.graphics.beginFill(0x000000);
			if(_value2 == 1 || _value2 == 3 || _value2 == 5) {
				_die2.graphics.drawCircle(85, 25, 4);
			}
			if(_value2 == 2 || _value2 == 3 || _value2 == 4 ||
				_value2 == 5 || _value2 == 6)
			{
				_die2.graphics.drawCircle(71, 11, 4);
				_die2.graphics.drawCircle(99, 39, 4);
			}
			if(_value2 == 4 || _value2 == 5 || _value2 == 6) {
				_die2.graphics.drawCircle(71, 39, 4);
				_die2.graphics.drawCircle(99, 11, 4);
			}
			if(_value2 == 6) {
				_die2.graphics.drawCircle(71, 25, 4);
				_die2.graphics.drawCircle(99, 25, 4);
			}
		}
		
	}
}

